package com.collections.www;

import java.util.*;

public class TeacherTest {
    public static void main(String[] args) {
        test01();
        test02();
    }
    //treeset输出时要排序 所以在存入对象时 ，需要实现comparable接口
    //set 内不重复 所以空对象会被当做一个 传入set

    /**
     * 集合工具类：Comparable接口
     */
    private static void test02() {
        List<Teacher>lst0=new ArrayList<>();
        lst0.add(new Teacher("zhangsan","NAN",10));
        lst0.add(new Teacher("lisi","NAN",20));
        lst0.add(new Teacher("wangwu","NAN",30));

        Collections.sort(lst0);

        for (Teacher teacher:lst0){
            System.out.println(teacher);
        }


    }
    /**
     * 集合工具类：Comparable接口和TreeSet
     */
    private static void test01() {
        Set<Teacher>set=new TreeSet<>();
        Teacher tea0=new Teacher();
        set.add(tea0);
        Teacher tea1=new Teacher();
        set.add(tea1);
        for (Teacher t:set){
            System.out.println(" "+t);
        }
    }

}
class Teacher implements Comparable<Teacher>{
    String name;
    String sex;
    int id;

    public String toString() {
        return "Student{" +
                "Name='" + name + '\'' +
                ", Sex='" + sex + '\'' +
                ", Id=" + id +
                '}';
    }
    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getSex() {
        return sex;
    }

    public void setSex(String sex) {
        this.sex = sex;
    }

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public Teacher(String name, String sex, int id) {
        this.name = name;
        this.sex = sex;
        this.id = id;
    }
    public Teacher(){}

    @Override
    public int compareTo(Teacher o) {
        return 0;
    }
}
